<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="/struts-tags"  prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>添加流程</title>
		<link href="css/table.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/openwindow.js"></script>
		<script type="text/javascript" src="js/select.js"></script>
		<script type="text/javascript">
		
function setValue(value,val){
	  var arr = eval(value);
	  var names = "";
	  var ids = "";
	  for(i=0;i<arr.length;i++){
	    ids =  ids + "," + arr[i].value;
	    names = names + "," + arr[i].name;
	  }
	  if(names.length>0){
	    names = names.substring(1);
	    ids =  ids.substring(1);
	  }
	  document.getElementById(val+"names").value=names;
	  document.getElementById(val+"ids").value=ids;
	}
	
	function selectUser(val){
		var url="getGrouphome.action?status="+val;
		openWindow(url,700,400);
	}
function getOldValue(val){
	  var ids=document.getElementById(val+"ids").value;
  	  var names=document.getElementById(val+"names").value;
      var array="";
  if(ids!=''&&ids!='null'){
  var idarray=ids.split(",");
  var namearray=names.split(",");
  for(var i=0;i<idarray.length;i++){
  		if(i==0){
  			array+="{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  		}else{
  	      array+=",{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  	   } 
  }
  }
	  return array;
	}
		
function selectorg(val){
			var url="orgByFlow.action?status="+val;
			openWindow(url,650,550);
		}
		
		function saveworkflow(){
			var typeId =$("#typeId").val();
			var title=$("#title").val();
			var formId=$("#formId").val();			
			if(typeId==''||typeId=='null'){
				alert('请选择流程分类！');
				return;
			}
			if(title==''||title=='null'){
				alert('流程名称不能为空！');
				return;
			}
			if(formId==''||formId=='null'){
				alert('请选择表单类型！');
				return;
			}
			var obj = document.getElementById("obj2");
	       var array = getSelectArray(obj);
		     setformValue(array);
			$.post("saveWorkFlow.action",$("form").serialize(),function(data){
					if(data=='success'){
						alert("添加成功");
						window.close();
						window.opener.location.href="getWorkFlows.action";
					}else{
						alert("添加失败！");
					}
				});
			}
function setformValue(value){
  var arr = eval(value);
  var names = "";
  var ids = "";
  for(i=0;i<arr.length;i++){
    ids =  ids + "," + arr[i].value;
    names = names + "," + arr[i].name;
  }
  if(names.length>0){
    names = names.substring(1);
    ids =  ids.substring(1);
  }
  document.getElementById("propertyid").value=ids;
}

function changeFormProporty(val){
	if(val!=''){
	var param={"formId":val};
	$.post("getFormProportyByFormId.action",param,function(data){
		var list=data.proportyList;
		var obj1=document.getElementById("obj1");
		var obj2=document.getElementById("obj2")
		clear(obj1);
		clear(obj2);
		for(var i=0;i<list.length;i++){
			addItem(obj1,list[i].id,list[i].proportyName);
		}
	},"json");
	}
}
		</script>
	</head>   
	<body>
		<table align="center" border="0" cellpadding="0" cellspacing="0"
			width="98%">
			<tbody>
				<tr>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
					<td style="background: url('image/wsoa_window_002.gif');">
						<table border="0" cellpadding="0" cellspacing="0">
							<tbody>
								<tr>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"
										width="10">
										<img src="image/center_19.gif">
									</td>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"></td>
									<td>工作流程 &gt; 流程管理 &gt; 流程定义 &gt;添加</td>
								</tr>
							</tbody>
						</table>
					</td>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
				</tr>
				<tr>
					<td style="background: url('image/wsoa_window_010.gif');" width="1">
						&nbsp;
					</td>
					<td>
					
						<form name="" id="saveTaskFrom" method="post" action="">
								<input type="hidden" id="propertyid" name="propertyid">
							<table style="width: 99%;" align="center">
								<tbody>
									<tr>
										<td>
											<table style="width: 100%;" class="table5 bgcolor5"
												align="center">
												<tbody>
													<tr>
														<td align="right" class="table5">
															<font color="red">*</font>流程分类
														</td>
														<td  class="table5">
															<s:select list="flowtypelist" id="typeId" cssStyle="width:40%" listKey="id" listValue="name" headerKey="" headerValue="--请选择流程类型--" name="workflow.typeId" value="workflow.typeId" theme="simple"></s:select>
														</td>
													</tr>
													<tr>
														<td align="right"  class="table5">
															<font color="red">*</font>流程名称
														</td>
														<td colspan="3"  class="table5">
															<input name="workflow.name" id="title" maxlength="50" style="width: 70%" title="该输入项的最大长度是100" type="text">
														</td>
													</tr>
													<tr>
														<td align="right"  class="table5">
															 适用范围
														</td>
														<td colspan="3"  class="table5">
															<textarea readonly="readonly" id="onames" name="names" style="width:95%;height:25px;">${names }</textarea><br/>
													    	<input type="hidden" id="oids" name="orgs" value="${orgs}">
													    	&nbsp;<a href="javascript:selectorg('o')">添加部门</a>
														</td>
													</tr>
													<tr>
														<td align="right"  class="table5">
															  适用范围
														</td>
														<td colspan="3"  class="table5">
															<textarea readonly="readonly" id="snames" name="actornames" style="width:95%;height:25px;">${actornames }</textarea><br/>
													    	<input type="hidden" id="sids" name="actorids" value="${actorids}">
													    	&nbsp;<a href="javascript:selectUser('s')">添加人员</a>
														</td>
													</tr>
													<tr>
														<td align="right"  class="table5">
															<font color="red">*</font>表单类型
														</td>
														<td colspan="3"  class="table5">
															<s:select list="formList" onchange="changeFormProporty(this.value)" id="formId" name="workflow.formId" value="workflow.formId" listKey="id" listValue="name" headerKey="" headerValue="--请选择表单类型--" theme="simple"></s:select>
														</td>
													</tr>
												</tbody>
											</table>
										</td>
									</tr>
									<tr>
									<td>
										<table style="width: 100%;" class="table5 bgcolor5"
												align="center">
												<tbody>
													<tr>
														<td class="table5" align="right" width="100">备  注 </td>
														<td  class="table5" align="left">
															<textarea name="workflow.note" id="content"
																style="width: 95%; height:70px;" onkeyup="textLength(this,200);"></textarea>
														</td>
													</tr>
												</tbody>
											</table>
										</td>
									</tr>
									<tr>
									<td>
										<table style="width: 100%;" class="table5 bgcolor5">
											<tr>
														<td align="right">
															发起时不填的字段
														</td>
														<td>
															<div style="float: left;">
																<select name="possible" id="obj1" size="4" MULTIPLE
																	style="width: 130px; height: 260px;">

																</select>
															</div>
															<div style="float: left; margin-top: 100px;">
																<input type="button" onclick="func1()" class="button_02"
																	value=">">
																<br>
																<br>
																<input type="button" onclick="func3()" class="button_02"
																	value=">>">
																<br>
																<br>
																<input type="button" class="button_02" onclick="func2()" value="<"> <br><br>
									                  <input type="button" width="25px" onclick="func4()" class="button_02" value="<<">
									                  <br /><br />
													</div>
									                
									                  <select name="chosen" id="obj2" size="4" MULTIPLE style="width: 130px;height:260px">
									                     
									                  </select>
									                </td>
									              </tr>  
											</table>
									</td>
									</tr>
								</tbody>
							</table>
							<table style="width: 99%;" align="center">
								<tbody>
									<tr>
										<td align="center">
											<span id="errorId"></span>
										</td>
									</tr>
									<tr>
										<td align="center">
											<input accesskey="t" value="提交" style="background: url('image/button_02.gif');" onClick="saveworkflow();" class="button_02" type="button">
											<input class="button_02" value="取消" accesskey="c" style="background: url('image/button_02.gif');" onClick="window.close();" type="button">
										</td>
									</tr>
								</tbody>
							</table>
						</form>
					</td>
					<td style="background: url('image/wsoa_window_006.gif');" width="1">
						&nbsp;
					</td>
				</tr>
				<tr>
					<td height="1" width="1">
						<img src="image/wsoa_window_009.gif" height="16" width="14">
					</td>
					<td style="background: url('image/wsoa_window_008.gif');"
						height="1"></td>
					<td height="1" width="1">
						<img src="image/wsoa_window_007.gif" height="16" width="12">
					</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>